package com.gxufl.dao;

import java.util.List;




import com.gxufl.entity.Notice;
import com.gxufl.entity.Room;
import com.gxufl.util.JdbcUtil;

public class RoomDao {
	
	
	/**
	 * 查询方法
	 * @param name
	 * @param showdate
	 * @return
	 */
	public List<Room> findList(String name) {
		String sql = "select * from movie_room where 1";
		
		if (name != null && !name.isEmpty()) {
			sql = sql + " and name like '%" + name + "%'";
		}
		
		return JdbcUtil.query(sql, Room.class);
	}
	
	/**
	 * 只返回一个结果，如果找不到，返回null
	 * @param name
	 * @return
	 */
	public Room findOne(String name) {
		String sql = "select * from movie_room where 1";
		List<Room> list = JdbcUtil.query(sql, Room.class);
		if (list.size() == 1) {
			return list.get(0);
		}
		return null;
	}

	/**
	 * 保存方法
	 * @param room
	 */
	public Room save(Room room) {
		// TODO: (完成) 通过dbutil保存海报信息到数据库表movie_notice中
	
		boolean isOK = JdbcUtil.save(room);
		
		Room _room = JdbcUtil.query("select * from movie_room where name='"+room.name+"'", Room.class).get(0);
		
		if (isOK) {
			System.out.println("保存“"+room.name+"”成功");
		} else {
			System.out.println("保存“"+room.name+"”失败");
		}
		
		return _room;
	}

	/**
	 * 删除方法
	 * @param name 名称
	 */
	public void delete(String name) {
		// TODO:（完成） 通过dbutil删除海报信息
		
		Room room = findOne(name);
		boolean isOK = JdbcUtil.delete(room.id, "room");
		
		// TODO: 删除关联座位表记录
		
		System.out.println(isOK?"删除成功！":"删除失败");
	}

}
